***preamble

clear
clear matrix
clear mata
set maxvar 30000

***load data

use "${path}\data\gss\gss.dta"

***prepare outcomes (scientific, religious and political outcomes are coded such that an increase in the variable implies an increase in scientific correctness, religiosity, political conservatism)

gen evo_approval = evolved
recode evo_approval (2=0) (.d=0) (.n=.) (.i=.)
label variable evo_approval "Evolution Belief"

gen evolved1_recode = evolved1
recode evolved1_recode (2=0) (.d=0) (.n=.)  (.i=.)

gen evolved2_recode = evolved2
recode evolved2_recode (2=0) (.d=0) (.n=.)  (.i=.)

replace evo_approval= evolved1_recode if evo_approval==.
replace evo_approval= evolved2_recode if evo_approval==.

gen evo_approval2 = evolved
recode evo_approval2 (2=0) (.d=.) (.n=.) (.i=.)
label variable evo_approval2 "Evolution Belief"

gen evolved1_recode2 = evolved1
recode evolved1_recode2 (2=0) (.d=.) (.n=.)  (.i=.)

gen evolved2_recode2 = evolved2
recode evolved2_recode2 (2=.) (.d=.) (.n=.)  (.i=.)

replace evo_approval2= evolved1_recode2 if evo_approval2==.
replace evo_approval2= evolved2_recode2 if evo_approval2==.

gen evo_approval3 = evolved
recode evo_approval3 (2=0) (.d=0) (.n=.) (.i=.)
label variable evo_approval3 "Evolution Belief"

gen evolved1_recode3 = evolved1
recode evolved1_recode3 (2=0) (.d=0) (.n=.)  (.i=.)

replace evo_approval3= evolved1_recode3 if evo_approval3==.

recode hotcore (2=0)  (.d=0) (.n=.) (.i=.)
label variable hotcore "Earth"
recode radioact (2=1) (1=0) (.d=0) (.n=.) (.i=.)
label variable radioact "Radioactivity"
recode boyorgrl (2=0)  (.d=0) (.n=.) (.i=.)
label variable boyorgrl "Reproduction"
recode lasers (2=1) (1=0) (.d=0) (.n=.) (.i=.)
label variable lasers "Lasers"
recode electron (2=0) (.d=0) (.n=.) (.i=.)
label variable electron "Electrons"
recode viruses (2=1) (1=0) (.d=0) (.n=.) (.i=.)
label variable viruses "Antibiotics"
recode bigbang (2=0) (.d=0) (.n=.) (.i=.)
recode bigbang1 (2=0) (.d=0) (.n=.) (.i=.)
recode bigbang2 (2=0) (.d=0) (.n=.) (.i=.)
replace bigbang=bigbang1 if bigbang==.
replace bigbang=bigbang2 if bigbang==.
label variable bigbang "Universe"
recode condrift (2=0) (.d=0) (.n=.) (.i=.)
label variable condrift "Tectonics"
recode earthsun (2=0) (.d=0) (.n=.) (.i=.)
label variable earthsun "Sun"

egen placebo_share_correct=rowmean(hotcore radioact boyorgrl lasers electron viruses bigbang condrift earthsun)
label variable placebo_share_correct "Non-Evolution Scientific Topics: Average"

recode god (6=1) (5=1) (4=1) (3=1) (2=0) (1=0) (.d=0) (.n=.) (.i=.)
label variable god "God"

recode bible (1=1) (2=1) (3=0) (4=0) (.d=0) (.n=.) (.i=.)
label variable bible "Bible"

recode postlife (1=1) (2=0) (.d=0) (.n=.) (.i=.) 
label variable postlife "Afterlife"

recode reborn (2=0) (.d=0) (.n=.) (.i=.)
label variable reborn "Rebirth"

recode reliten (4=0) (3=1) (2=0) (1=1) (.d=0) (.n=.) (.i=.)
label variable reliten "Strong Believer"

recode relig (2=1) (3=1) (4=0) (5=1) (6=1) (7=1) (8=1) (9=1) (10=1) (11=1) (12=1) (13=1) (98=0) (.d=0) (99=.) (.i=.)
label variable relig "Religious Affiliation"

recode attend (9=0) (8=1) (7=1) (6=1) (5=1) (4=1) (3=0) (2=0) (1=0) (.d=0) (.n=.) (.i=.)
label variable attend "Church-going"

recode relactiv (11=1) (10=1) (9=1) (8=1) (7=1) (6=1) (5=1) (4=0) (3=0) (2=0) (1=0) (.d=0) (.n=.) (.i=.)
label variable relactiv "Church Activities"

recode pray (6=0) (5=0) (4=1) (3=1) (2=1) (1=1) (.d=0) (.n=.) (.i=.)  
label variable pray "Personal Prayer"

recode savesoul (2=0) (.d=0) (.n=.) (.i=.)
label variable savesoul "Missionize"

recode sprtprsn (4=0) (3=0) (2=1) (1=1) (.d=0) (.n=.) (.i=.)
label variable sprtprsn "Spiritual Person"

recode relpersn (4=0) (3=0) (2=1) (1=1) (.d=0) (.n=.) (.i=.)
label variable relpersn "Religious Person"

recode fund (3=0) (2=0) (1=1) (.d=0) (.n=.) (.i=.)
label variable fund "Fundamentalist"

egen placebo_religiosity_average=rowmean(god bible postlife reborn reliten relig attend relactiv pray savesoul sprtprsn relpersn fund)
label variable placebo_religiosity_average "Religious Outcomes: Average"

recode partyid (1=0) (2=0) (3=0) (4=1) (5=1) (6=1) (7=0) (.d=0) (.i=.)
label variable partyid "Republican"

recode polviews (1=0) (2=0) (3=0) (4=0) (5=1) (6=1) (7=1) (.d=0) (.i=.)
label variable polviews "Conservative"

recode prayer (2=1) (1=0) (.d=0) (.n=.) (.i=.)  
label variable prayer "Prayer in Public Schools"

recode sexeduc (2=0) (3=0) (.d=0) (.n=.) (.i=.) 
label variable sexeduc "Sex Education in Public Schools"

recode marhomo (2=1) (3=0) (4=0) (5=0) (.d=0) (.i=.)
label variable marhomo "Same-Sex Marriage"

recode abany (2=0) (.d=0) (.i=.)
label variable abany "Abortion"

recode grass (2=0) (.d=0) (.i=.)
label variable grass "Marijuana Legalization"

recode cappun (2=0) (.d=0) (.i=.)
label variable cappun "Capital Punishment"

recode gunlaw (2=0) (.d=0) (.i=.)
label variable gunlaw "Gun Control"

recode letin1 (1=1) (2=1) (3=0) (4=0) (5=0) (.d=0) (.i=.)
recode letin1a (1=1) (2=1) (3=0) (4=0) (5=0) (.d=0) (.i=.)
replace letin1=letin1a if letin1==.
label variable letin1 "Immigration"

recode natenvir (1=1) (2=0) (3=0) (.d=0) (.i=.)
recode natenviy (1=1) (2=0) (3=0) (.d=0) (.i=.)
replace natenvir=natenviy if natenvir==.
label variable natenvir "Environment"

recode natenrgy (1=1) (2=0) (3=0) (.d=0) (.i=.)
label variable natenrgy "Alternative Energy Sources"

recode nateduc (1=1) (2=0) (3=0) (.d=0) (.i=.)
recode nateducy (1=1) (2=0) (3=0) (.d=0) (.i=.)
replace nateduc=nateducy if nateduc==.
label variable nateduc "Education"

recode natsci (1=1) (2=0) (3=0) (.d=0) (.i=.)
label variable natsci "Scientific Research"

recode eqwlth (1=1) (2=1) (3=1) (4=0) (5=0) (6=0) (7=0) (.d=0) (.i=.)
label variable eqwlth "Reducing Income Differences"

recode natfare (1=1) (2=0) (3=0) (.d=0) (.i=.)
recode natfarey (1=1) (2=0) (3=0) (.d=0) (.i=.)
replace natfare=natfarey if natfare==.
label variable natfare "Assistance to the Poor"

recode natrace (1=1) (2=0) (3=0) (.d=0) (.i=.)
recode natracey (1=1) (2=0) (3=0) (.d=0) (.i=.)
replace natrace=natracey if natrace==.
label variable natrace "Conditions of Blacks"

foreach v of varlist partyid polviews prayer sexeduc marhomo abany grass cappun gunlaw letin1 natenvir natenrgy nateduc natsci eqwlth natfare natrace {
tab polviews, sum(`v') 
}

foreach v of varlist sexeduc marhomo abany grass gunlaw letin1 natenvir natenrgy nateduc natsci eqwlth natfare natrace {
gen `v'_recode = `v'
recode `v'_recode (1=0) (0=1)
}

foreach v of varlist partyid polviews prayer cappun {
gen `v'_recode = `v'
}

egen placebo_political_average=rowmean(partyid_recode polviews_recode prayer_recode sexeduc_recode marhomo_recode abany_recode grass_recode cappun_recode gunlaw_recode letin1_recode natenvir_recode natenrgy_recode nateduc_recode natsci_recode eqwlth_recode natfare_recode natrace_recode)
label variable placebo_political_average "Political Outcomes: Average"

label variable partyid_recode "Republican"
label variable polviews_recode "Conservative"
label variable prayer_recode "Prayer in Public Schools"
label variable sexeduc_recode "Sex Education in Public Schools"
label variable marhomo_recode "Same-Sex Marriage"
label variable abany_recode "Abortion"
label variable grass_recode "Marijuana Legalization"
label variable cappun_recode "Capital Punishment"
label variable gunlaw_recode "Gun Control"
label variable letin1_recode "Immigration"
label variable natenvir_recode "Environment"
label variable natenrgy_recode "Alternative Energy Sources"
label variable nateduc_recode "Education"
label variable natsci_recode "Scientific Research"
label variable eqwlth_recode "Reducing Income Differences"
label variable natfare_recode "Assistance to the Poor"
label variable natrace_recode "Conditions of Blacks"

recode consci (1=1) (2=1) (3=0) (.d=0) (.i=.)
label variable consci "Confidence in Science"

recode intsci (1=1) (2=1) (3=0) (.d=0) (.i=.)
label variable intsci "Interest in Science"

recode advfront (1=1) (2=1) (3=0) (4=0) (.d=0) (.i=.)
label variable advfront "Science is Necessary"

egen placebo_share_correct_sciatt=rowmean(consci intsci advfront)
label var placebo_share_correct_sciatt "Science Attitudes: Average"

***cut dataset and prepare for treatment definition

drop if cohort==.n
rename fipsstat16 state16
drop if state16==.
drop if state16<1
gen highschoolentryyear=cohort+14
keep if highschoolentryyear>1990
keep if highschoolentryyear<2010
drop if evo_approval==.

***prepare treatments

gen evolution_score=.
replace evolution_score= 9 if state16==1 & highschoolentryyear<2005
replace evolution_score= 21 if state16==1 & highschoolentryyear>=2005
replace evolution_score= 48 if state16==2 & highschoolentryyear<2006
replace evolution_score= 59 if state16==2 & highschoolentryyear>=2006
replace evolution_score= 82 if state16==4 & highschoolentryyear<2005
replace evolution_score= 82 if state16==4 & highschoolentryyear>=2005
replace evolution_score= 55 if state16==5 & highschoolentryyear<2005
replace evolution_score= 66 if state16==5 & highschoolentryyear>=2005
replace evolution_score= 100 if state16==6
replace evolution_score= 86 if state16==8 & highschoolentryyear<2009
replace evolution_score= 82 if state16==8 & highschoolentryyear>=2009
replace evolution_score= 100 if state16==9 & highschoolentryyear<2004
replace evolution_score= 59 if state16==9 & highschoolentryyear>=2004
replace evolution_score= 91 if state16==10 & highschoolentryyear<2006
replace evolution_score= 80 if state16==10 & highschoolentryyear>=2006
replace evolution_score= 80 if state16==11 & highschoolentryyear<2006
replace evolution_score= 96 if state16==11 & highschoolentryyear>=2006
replace evolution_score= 16 if state16==12 & highschoolentryyear<2008
replace evolution_score= 91 if state16==12 & highschoolentryyear>=2008
replace evolution_score= 7 if state16==13 & highschoolentryyear<2004
replace evolution_score= 66 if state16==13 & highschoolentryyear>=2004
replace evolution_score= 91 if state16==15 & highschoolentryyear<2005
replace evolution_score= 75 if state16==15 & highschoolentryyear>=2005
replace evolution_score= 82 if state16==16 & highschoolentryyear<2007
replace evolution_score= 82 if state16==16 & highschoolentryyear>=2007
replace evolution_score= 45 if state16==17 & highschoolentryyear<2004
replace evolution_score= 82 if state16==17 & highschoolentryyear>=2004
replace evolution_score= 100 if state16==18 & highschoolentryyear<2006
replace evolution_score= 96 if state16==18 & highschoolentryyear>=2006
replace evolution_score= 77 if state16==19 & highschoolentryyear>=2007
replace evolution_score= 0 if state16==20 & highschoolentryyear<2007
replace evolution_score= 96 if state16==20 & highschoolentryyear>=2007
replace evolution_score= 55 if state16==21 & highschoolentryyear<2006
replace evolution_score= 55 if state16==21 & highschoolentryyear>=2006
replace evolution_score= 64 if state16==22 & highschoolentryyear<2005
replace evolution_score= 27 if state16==22 & highschoolentryyear>=2005
replace evolution_score= 30 if state16==23 & highschoolentryyear<2007
replace evolution_score= 68 if state16==23 & highschoolentryyear>=2007
replace evolution_score= 77 if state16==24 & highschoolentryyear<2002
replace evolution_score= 73 if state16==24 & highschoolentryyear>=2002
replace evolution_score= 82 if state16==25 & highschoolentryyear<2006
replace evolution_score= 84 if state16==25 & highschoolentryyear>=2006
replace evolution_score= 84 if state16==26 & highschoolentryyear<2000
replace evolution_score= 80 if state16==26 & highschoolentryyear>=2000
replace evolution_score= 86 if state16==27 & highschoolentryyear<2009
replace evolution_score= 89 if state16==27 & highschoolentryyear>=2009
replace evolution_score= 5 if state16==28 & highschoolentryyear<2008
replace evolution_score= 86 if state16==28 & highschoolentryyear>=2008
replace evolution_score= 82 if state16==29 & highschoolentryyear<2008
replace evolution_score= 78 if state16==29 & highschoolentryyear>=2008
replace evolution_score= 82 if state16==30 & highschoolentryyear<2006
replace evolution_score= 75 if state16==30 & highschoolentryyear>=2006
replace evolution_score= 66 if state16==31 
replace evolution_score= 70 if state16==32 & highschoolentryyear<2004
replace evolution_score= 77 if state16==32 & highschoolentryyear>=2004
replace evolution_score= 23 if state16==33 & highschoolentryyear<2006
replace evolution_score= 91 if state16==33 & highschoolentryyear>=2006
replace evolution_score= 100 if state16==34 & highschoolentryyear<2002
replace evolution_score= 100 if state16==34 & highschoolentryyear>=2002
replace evolution_score= 73 if state16==35 & highschoolentryyear<2003
replace evolution_score= 91 if state16==35 & highschoolentryyear>=2003
replace evolution_score= 68 if state16==36 
replace evolution_score= 100 if state16==37 & highschoolentryyear<2004
replace evolution_score= 82 if state16==37 & highschoolentryyear>=2004
replace evolution_score= 9 if state16==38 & highschoolentryyear<2006
replace evolution_score= 64 if state16==38 & highschoolentryyear>=2006
replace evolution_score= 30 if state16==39 & highschoolentryyear<2006
replace evolution_score= 86 if state16==39 & highschoolentryyear>=2006
replace evolution_score= 25 if state16==40 & highschoolentryyear<2005
replace evolution_score= 25 if state16==40 & highschoolentryyear>=2005
replace evolution_score= 82 if state16==41 & highschoolentryyear<2009
replace evolution_score= 82 if state16==41 & highschoolentryyear>=2009
replace evolution_score= 91 if state16==42 & highschoolentryyear<2002
replace evolution_score= 96 if state16==42 & highschoolentryyear>=2002
replace evolution_score= 100 if state16==44 & highschoolentryyear<2006
replace evolution_score= 82 if state16==44 & highschoolentryyear>=2006
replace evolution_score= 95 if state16==45 & highschoolentryyear<2005
replace evolution_score= 91 if state16==45 & highschoolentryyear>=2005
replace evolution_score= 82 if state16==46 & highschoolentryyear<2005
replace evolution_score= 77 if state16==46 & highschoolentryyear>=2005
replace evolution_score= 2 if state16==47 & highschoolentryyear<2007
replace evolution_score= 55 if state16==47 & highschoolentryyear>=2007
replace evolution_score= 64 if state16==48 & highschoolentryyear<2009
replace evolution_score= 46 if state16==48 & highschoolentryyear>=2009
replace evolution_score= 82 if state16==49 & highschoolentryyear<2003
replace evolution_score= 82 if state16==49 & highschoolentryyear>=2003
replace evolution_score= 86 if state16==50 & highschoolentryyear<2000
replace evolution_score= 86 if state16==50 & highschoolentryyear>=2000
replace evolution_score= 50 if state16==51 & highschoolentryyear<2003
replace evolution_score= 68 if state16==51 & highschoolentryyear>=2003
replace evolution_score= 86 if state16==53 & highschoolentryyear<2005
replace evolution_score= 86 if state16==53 & highschoolentryyear>=2005
replace evolution_score= 2 if state16==54 & highschoolentryyear<2008
replace evolution_score= 46 if state16==54 & highschoolentryyear>=2008
replace evolution_score= 55 if state16==55 
replace evolution_score= 36 if state16==56 & highschoolentryyear<2003
replace evolution_score= 61 if state16==56 & highschoolentryyear>=2003
gen evo_score=evolution_score/100
label variable evo_score "Evolution Score"

gen evolution_score_dosage=.
replace evolution_score_dosage= 9 if state16==1 & highschoolentryyear<2002
replace evolution_score_dosage= 12 if state16==1 & highschoolentryyear==2002
replace evolution_score_dosage= 15 if state16==1 & highschoolentryyear==2003
replace evolution_score_dosage= 18 if state16==1 & highschoolentryyear==2004
replace evolution_score_dosage= 21 if state16==1 & highschoolentryyear>=2005
replace evolution_score_dosage= 48 if state16==2 & highschoolentryyear<2003
replace evolution_score_dosage= 50.75 if state16==2 & highschoolentryyear==2003
replace evolution_score_dosage= 53.5 if state16==2 & highschoolentryyear==2004
replace evolution_score_dosage= 56.25 if state16==2 & highschoolentryyear==2005
replace evolution_score_dosage= 59 if state16==2 & highschoolentryyear>=2006
replace evolution_score_dosage= 82 if state16==4 & highschoolentryyear<2005
replace evolution_score_dosage= 82 if state16==4 & highschoolentryyear>=2005
replace evolution_score_dosage= 55 if state16==5 & highschoolentryyear<2002
replace evolution_score_dosage= 57.75 if state16==5 & highschoolentryyear==2002
replace evolution_score_dosage= 60.5 if state16==5 & highschoolentryyear==2003
replace evolution_score_dosage= 63.25 if state16==5 & highschoolentryyear==2004
replace evolution_score_dosage= 66 if state16==5 & highschoolentryyear>=2005
replace evolution_score_dosage= 100 if state16==6
replace evolution_score_dosage= 86 if state16==8 & highschoolentryyear<2006
replace evolution_score_dosage= 85 if state16==8 & highschoolentryyear==2006
replace evolution_score_dosage= 84 if state16==8 & highschoolentryyear==2007
replace evolution_score_dosage= 83 if state16==8 & highschoolentryyear==2008
replace evolution_score_dosage= 82 if state16==8 & highschoolentryyear>=2009
replace evolution_score_dosage= 100 if state16==9 & highschoolentryyear<2001
replace evolution_score_dosage= 89.75 if state16==9 & highschoolentryyear==2001
replace evolution_score_dosage= 79.5 if state16==9 & highschoolentryyear==2002
replace evolution_score_dosage= 69.25 if state16==9 & highschoolentryyear==2003
replace evolution_score_dosage= 59 if state16==9 & highschoolentryyear>=2004
replace evolution_score_dosage= 91 if state16==10 & highschoolentryyear<2003
replace evolution_score_dosage= 88.25 if state16==10 & highschoolentryyear==2003
replace evolution_score_dosage= 85.5 if state16==10 & highschoolentryyear==2004
replace evolution_score_dosage= 82.75 if state16==10 & highschoolentryyear==2005
replace evolution_score_dosage= 80 if state16==10 & highschoolentryyear>=2006
replace evolution_score_dosage= 80 if state16==11 & highschoolentryyear<2003
replace evolution_score_dosage= 84 if state16==11 & highschoolentryyear==2003
replace evolution_score_dosage= 88 if state16==11 & highschoolentryyear==2004
replace evolution_score_dosage= 92 if state16==11 & highschoolentryyear==2005
replace evolution_score_dosage= 96 if state16==11 & highschoolentryyear>=2006
replace evolution_score_dosage= 16 if state16==12 & highschoolentryyear<2005
replace evolution_score_dosage= 34.75 if state16==12 & highschoolentryyear==2005
replace evolution_score_dosage= 53.5 if state16==12 & highschoolentryyear==2006
replace evolution_score_dosage= 72.25 if state16==12 & highschoolentryyear==2007
replace evolution_score_dosage= 91 if state16==12 & highschoolentryyear>=2008
replace evolution_score_dosage= 7 if state16==13 & highschoolentryyear<2001
replace evolution_score_dosage= 21.75 if state16==13 & highschoolentryyear==2001
replace evolution_score_dosage= 36.5 if state16==13 & highschoolentryyear==2002
replace evolution_score_dosage= 51.25 if state16==13 & highschoolentryyear==2003
replace evolution_score_dosage= 66 if state16==13 & highschoolentryyear>=2004
replace evolution_score_dosage= 91 if state16==15 & highschoolentryyear<2002
replace evolution_score_dosage= 87 if state16==15 & highschoolentryyear==2002
replace evolution_score_dosage= 83 if state16==15 & highschoolentryyear==2003
replace evolution_score_dosage= 79 if state16==15 & highschoolentryyear==2004
replace evolution_score_dosage= 75 if state16==15 & highschoolentryyear>=2005
replace evolution_score_dosage= 82 if state16==16 & highschoolentryyear<2007
replace evolution_score_dosage= 82 if state16==16 & highschoolentryyear>=2007
replace evolution_score_dosage= 45 if state16==17 & highschoolentryyear<2001
replace evolution_score_dosage= 54.25 if state16==17 & highschoolentryyear==2001
replace evolution_score_dosage= 63.5 if state16==17 & highschoolentryyear==2002
replace evolution_score_dosage= 72.25 if state16==17 & highschoolentryyear==2003
replace evolution_score_dosage= 82 if state16==17 & highschoolentryyear>=2004
replace evolution_score_dosage= 100 if state16==18 & highschoolentryyear<2003
replace evolution_score_dosage= 99 if state16==18 & highschoolentryyear==2003
replace evolution_score_dosage= 98 if state16==18 & highschoolentryyear==2004
replace evolution_score_dosage= 97 if state16==18 & highschoolentryyear==2005
replace evolution_score_dosage= 96 if state16==18 & highschoolentryyear>=2006
replace evolution_score_dosage= 77 if state16==19 & highschoolentryyear>=2007
replace evolution_score_dosage= 0 if state16==20 & highschoolentryyear<2004
replace evolution_score_dosage= 24 if state16==20 & highschoolentryyear==2004
replace evolution_score_dosage= 48 if state16==20 & highschoolentryyear==2005
replace evolution_score_dosage= 72 if state16==20 & highschoolentryyear==2006
replace evolution_score_dosage= 96 if state16==20 & highschoolentryyear>=2007
replace evolution_score_dosage= 55 if state16==21 & highschoolentryyear<2006
replace evolution_score_dosage= 55 if state16==21 & highschoolentryyear>=2006
replace evolution_score_dosage= 64 if state16==22 & highschoolentryyear<2002
replace evolution_score_dosage= 54.75 if state16==22 & highschoolentryyear==2002
replace evolution_score_dosage= 45.5 if state16==22 & highschoolentryyear==2003
replace evolution_score_dosage= 36.25 if state16==22 & highschoolentryyear==2004
replace evolution_score_dosage= 27 if state16==22 & highschoolentryyear>=2005
replace evolution_score_dosage= 30 if state16==23 & highschoolentryyear<2004
replace evolution_score_dosage= 39.5 if state16==23 & highschoolentryyear==2004
replace evolution_score_dosage= 49 if state16==23 & highschoolentryyear==2005
replace evolution_score_dosage= 58.5 if state16==23 & highschoolentryyear==2006
replace evolution_score_dosage= 68 if state16==23 & highschoolentryyear>=2007
replace evolution_score_dosage= 77 if state16==24 & highschoolentryyear<1999
replace evolution_score_dosage= 76 if state16==24 & highschoolentryyear==1999
replace evolution_score_dosage= 75 if state16==24 & highschoolentryyear==2000
replace evolution_score_dosage= 74 if state16==24 & highschoolentryyear==2001
replace evolution_score_dosage= 73 if state16==24 & highschoolentryyear>=2002
replace evolution_score_dosage= 82 if state16==25 & highschoolentryyear<2003
replace evolution_score_dosage= 82.5 if state16==25 & highschoolentryyear==2003
replace evolution_score_dosage= 83 if state16==25 & highschoolentryyear==2004
replace evolution_score_dosage= 83.5 if state16==25 & highschoolentryyear==2005
replace evolution_score_dosage= 84 if state16==25 & highschoolentryyear>=2006
replace evolution_score_dosage= 84 if state16==26 & highschoolentryyear<1997
replace evolution_score_dosage= 83 if state16==26 & highschoolentryyear==1997
replace evolution_score_dosage= 82 if state16==26 & highschoolentryyear==1998
replace evolution_score_dosage= 81 if state16==26 & highschoolentryyear==1999
replace evolution_score_dosage= 80 if state16==26 & highschoolentryyear>=2000
replace evolution_score_dosage= 86 if state16==27 & highschoolentryyear<2006
replace evolution_score_dosage= 86.75 if state16==27 & highschoolentryyear==2006
replace evolution_score_dosage= 87.5 if state16==27 & highschoolentryyear==2007
replace evolution_score_dosage= 88.25 if state16==27 & highschoolentryyear==2008
replace evolution_score_dosage= 89 if state16==27 & highschoolentryyear>=2009
replace evolution_score_dosage= 5 if state16==28 & highschoolentryyear<2005
replace evolution_score_dosage= 25.5 if state16==28 & highschoolentryyear==2005
replace evolution_score_dosage= 45.5 if state16==28 & highschoolentryyear==2006
replace evolution_score_dosage= 65.75 if state16==28 & highschoolentryyear==2007
replace evolution_score_dosage= 86 if state16==28 & highschoolentryyear>=2008
replace evolution_score_dosage= 82 if state16==29 & highschoolentryyear<2005
replace evolution_score_dosage= 81 if state16==29 & highschoolentryyear==2005
replace evolution_score_dosage= 80 if state16==29 & highschoolentryyear==2006
replace evolution_score_dosage= 79 if state16==29 & highschoolentryyear==2007
replace evolution_score_dosage= 78 if state16==29 & highschoolentryyear>=2008
replace evolution_score_dosage= 82 if state16==30 & highschoolentryyear<2003
replace evolution_score_dosage= 80.25 if state16==30 & highschoolentryyear==2003
replace evolution_score_dosage= 78.5 if state16==30 & highschoolentryyear==2004
replace evolution_score_dosage= 76.75 if state16==30 & highschoolentryyear==2005
replace evolution_score_dosage= 75 if state16==30 & highschoolentryyear>=2006
replace evolution_score_dosage= 66 if state16==31 
replace evolution_score_dosage= 70 if state16==32 & highschoolentryyear<2001
replace evolution_score_dosage= 71.75 if state16==32 & highschoolentryyear==2001
replace evolution_score_dosage= 73.5 if state16==32 & highschoolentryyear==2002
replace evolution_score_dosage= 75.25 if state16==32 & highschoolentryyear==2003
replace evolution_score_dosage= 77 if state16==32 & highschoolentryyear>=2004
replace evolution_score_dosage= 23 if state16==33 & highschoolentryyear<2003
replace evolution_score_dosage= 40 if state16==33 & highschoolentryyear==2003
replace evolution_score_dosage= 57 if state16==33 & highschoolentryyear==2004
replace evolution_score_dosage= 74 if state16==33 & highschoolentryyear==2005
replace evolution_score_dosage= 91 if state16==33 & highschoolentryyear>=2006
replace evolution_score_dosage= 100 if state16==34 & highschoolentryyear<2002
replace evolution_score_dosage= 100 if state16==34 & highschoolentryyear>=2002
replace evolution_score_dosage= 73 if state16==35 & highschoolentryyear<2000
replace evolution_score_dosage= 77.5 if state16==35 & highschoolentryyear==2000
replace evolution_score_dosage= 82 if state16==35 & highschoolentryyear==2001
replace evolution_score_dosage= 86.5 if state16==35 & highschoolentryyear==2002
replace evolution_score_dosage= 91 if state16==35 & highschoolentryyear>=2003
replace evolution_score_dosage= 68 if state16==36 
replace evolution_score_dosage= 100 if state16==37 & highschoolentryyear<2001
replace evolution_score_dosage= 95.5 if state16==37 & highschoolentryyear==2001
replace evolution_score_dosage= 91 if state16==37 & highschoolentryyear==2002
replace evolution_score_dosage= 86.5 if state16==37 & highschoolentryyear==2003
replace evolution_score_dosage= 82 if state16==37 & highschoolentryyear>=2004
replace evolution_score_dosage= 9 if state16==38 & highschoolentryyear<2003
replace evolution_score_dosage= 22.75 if state16==38 & highschoolentryyear==2003
replace evolution_score_dosage= 36.5 if state16==38 & highschoolentryyear==2004
replace evolution_score_dosage= 50.25 if state16==38 & highschoolentryyear==2005
replace evolution_score_dosage= 64 if state16==38 & highschoolentryyear>=2006
replace evolution_score_dosage= 30 if state16==39 & highschoolentryyear<2003
replace evolution_score_dosage= 44 if state16==39 & highschoolentryyear==2003
replace evolution_score_dosage= 58 if state16==39 & highschoolentryyear==2004
replace evolution_score_dosage= 72 if state16==39 & highschoolentryyear==2005
replace evolution_score_dosage= 86 if state16==39 & highschoolentryyear>=2006
replace evolution_score_dosage= 25 if state16==40 & highschoolentryyear<2005
replace evolution_score_dosage= 25 if state16==40 & highschoolentryyear>=2005
replace evolution_score_dosage= 82 if state16==41 & highschoolentryyear<2009
replace evolution_score_dosage= 82 if state16==41 & highschoolentryyear>=2009
replace evolution_score_dosage= 91 if state16==42 & highschoolentryyear<2002
replace evolution_score_dosage= 92.25 if state16==42 & highschoolentryyear==2002
replace evolution_score_dosage= 93.5 if state16==42 & highschoolentryyear==2002
replace evolution_score_dosage= 94.75 if state16==42 & highschoolentryyear==2002
replace evolution_score_dosage= 96 if state16==42 & highschoolentryyear>=2002
replace evolution_score_dosage= 100 if state16==44 & highschoolentryyear<2003
replace evolution_score_dosage= 95.5 if state16==44 & highschoolentryyear==2003
replace evolution_score_dosage= 91 if state16==44 & highschoolentryyear==2004
replace evolution_score_dosage= 86.5 if state16==44 & highschoolentryyear==2005
replace evolution_score_dosage= 82 if state16==44 & highschoolentryyear>=2006
replace evolution_score_dosage= 95 if state16==45 & highschoolentryyear<2002
replace evolution_score_dosage= 94 if state16==45 & highschoolentryyear==2002
replace evolution_score_dosage= 93 if state16==45 & highschoolentryyear==2003
replace evolution_score_dosage= 92 if state16==45 & highschoolentryyear==2004
replace evolution_score_dosage= 91 if state16==45 & highschoolentryyear>=2005
replace evolution_score_dosage= 82 if state16==46 & highschoolentryyear<2002
replace evolution_score_dosage= 80.75 if state16==46 & highschoolentryyear==2002
replace evolution_score_dosage= 79.5 if state16==46 & highschoolentryyear==2003
replace evolution_score_dosage= 78.25 if state16==46 & highschoolentryyear==2004
replace evolution_score_dosage= 77 if state16==46 & highschoolentryyear>=2005
replace evolution_score_dosage= 2 if state16==47 & highschoolentryyear<2004
replace evolution_score_dosage= 15.25 if state16==47 & highschoolentryyear==2004
replace evolution_score_dosage= 28.5 if state16==47 & highschoolentryyear==2005
replace evolution_score_dosage= 41.75 if state16==47 & highschoolentryyear==2006
replace evolution_score_dosage= 55 if state16==47 & highschoolentryyear>=2007
replace evolution_score_dosage= 64 if state16==48 & highschoolentryyear<2006
replace evolution_score_dosage= 59.5 if state16==48 & highschoolentryyear==2006
replace evolution_score_dosage= 55 if state16==48 & highschoolentryyear==2007
replace evolution_score_dosage= 50.5 if state16==48 & highschoolentryyear==2008
replace evolution_score_dosage= 46 if state16==48 & highschoolentryyear>=2009
replace evolution_score_dosage= 82 if state16==49 & highschoolentryyear<2003
replace evolution_score_dosage= 82 if state16==49 & highschoolentryyear>=2003
replace evolution_score_dosage= 86 if state16==50 & highschoolentryyear<2000
replace evolution_score_dosage= 86 if state16==50 & highschoolentryyear>=2000
replace evolution_score_dosage= 50 if state16==51 & highschoolentryyear<2000
replace evolution_score_dosage= 54.5 if state16==51 & highschoolentryyear==2000
replace evolution_score_dosage= 59 if state16==51 & highschoolentryyear==2001
replace evolution_score_dosage= 63.5 if state16==51 & highschoolentryyear==2002
replace evolution_score_dosage= 68 if state16==51 & highschoolentryyear>=2003
replace evolution_score_dosage= 86 if state16==53 & highschoolentryyear<2005
replace evolution_score_dosage= 86 if state16==53 & highschoolentryyear>=2005
replace evolution_score_dosage= 2 if state16==54 & highschoolentryyear<2005
replace evolution_score_dosage= 13 if state16==54 & highschoolentryyear==2005
replace evolution_score_dosage= 24 if state16==54 & highschoolentryyear==2006
replace evolution_score_dosage= 35 if state16==54 & highschoolentryyear==2007
replace evolution_score_dosage= 46 if state16==54 & highschoolentryyear>=2008
replace evolution_score_dosage= 2 if state16==55 
replace evolution_score_dosage= 36 if state16==56 & highschoolentryyear<2000
replace evolution_score_dosage= 42.25 if state16==56 & highschoolentryyear==2000
replace evolution_score_dosage= 48.5 if state16==56 & highschoolentryyear==2001
replace evolution_score_dosage= 54.75 if state16==56 & highschoolentryyear==2002
replace evolution_score_dosage= 61 if state16==56 & highschoolentryyear>=2003
gen evo_score_dosage=evolution_score_dosage/100
label variable evo_score_dosage "Evolution Score"

forvalues i=1/9 {
gen evo_score_`i' =0
replace evo_score_`i'=1 if evo_score>0.`i'
replace evo_score_`i'=. if evo_score==.
label variable evo_score_`i' "Evolution Score $>$ 0.`i'0"
}

gen more_evolution=0
replace more_evolution=1 if state16==1 | state16==2 | state16==5 | state16==11 | state16==12 | state16==13 | state16==17 | state16==20 | state16==23 | state16==25 | state16==27 | state16==28 | state16==32 |state16==33 | state16==35 | state16==38 | state16==39 | state16==42 |state16==47 | state16==51 | state16==54 | state16==56

gen less_evolution=0
replace less_evolution=1 if state16==8 | state16==9 | state16==10 | state16==15 | state16==18 | state16==22 | state16==24 | state16==26 | state16==29 | state16==30 | state16==37 | state16==44 | state16==45 | state16==46 | state16==48

gen equal_evolution=0
replace equal_evolution=1 if state16==4 | state16==6 | state16==16 | state16==19 | state16==21 | state16==31 | state16==34 | state16==36 | state16==40 | state16==41 | state16==49 | state16==50 | state16==53 | state16==55

gen first_treat=.
replace first_treat=2005 if state16==1
replace first_treat=2006 if state16==2
replace first_treat=2005 if state16==4
replace first_treat=2005 if state16==5
replace first_treat=2009 if state16==8
replace first_treat=2004 if state16==9
replace first_treat=2006 if state16==10
replace first_treat=2006 if state16==11
replace first_treat=2008 if state16==12
replace first_treat=2004 if state16==13
replace first_treat=2005 if state16==15
replace first_treat=2007 if state16==16
replace first_treat=2004 if state16==17
replace first_treat=2006 if state16==18
replace first_treat=2007 if state16==20
replace first_treat=2006 if state16==21
replace first_treat=2005 if state16==22
replace first_treat=2007 if state16==23
replace first_treat=2002 if state16==24
replace first_treat=2006 if state16==25
replace first_treat=2000 if state16==26
replace first_treat=2009 if state16==27
replace first_treat=2008 if state16==28
replace first_treat=2008 if state16==29
replace first_treat=2006 if state16==30
replace first_treat=2004 if state16==32
replace first_treat=2006 if state16==33
replace first_treat=2002 if state16==34
replace first_treat=2003 if state16==35
replace first_treat=2004 if state16==37
replace first_treat=2006 if state16==38
replace first_treat=2006 if state16==39
replace first_treat=2005 if state16==40
replace first_treat=2009 if state16==41
replace first_treat=2002 if state16==42
replace first_treat=2006 if state16==44
replace first_treat=2005 if state16==45
replace first_treat=2005 if state16==46
replace first_treat=2007 if state16==47
replace first_treat=2009 if state16==48
replace first_treat=2003 if state16==49
replace first_treat=2000 if state16==50
replace first_treat=2003 if state16==51
replace first_treat=2005 if state16==53
replace first_treat=2008 if state16==54
replace first_treat=2003 if state16==56
replace first_treat=0 if first_treat==.
rename id number
gene id=_n

gen trend=0
replace trend= highschoolentryyear - 2005 if state16==1
replace trend= highschoolentryyear - 2006 if state16==2
replace trend= highschoolentryyear - 2005 if state16==5
replace trend= highschoolentryyear - 2009 if state16==8
replace trend= highschoolentryyear - 2004 if state16==9
replace trend= highschoolentryyear - 2006 if state16==10
replace trend= highschoolentryyear - 2006 if state16==11
replace trend= highschoolentryyear - 2008 if state16==12
replace trend= highschoolentryyear - 2004 if state16==13
replace trend= highschoolentryyear - 2005 if state16==15
replace trend= highschoolentryyear - 2004 if state16==17
replace trend= highschoolentryyear - 2006 if state16==18
replace trend= highschoolentryyear - 2007 if state16==19
replace trend= highschoolentryyear - 2007 if state16==20
replace trend= highschoolentryyear - 2005 if state16==22
replace trend= highschoolentryyear - 2007 if state16==23
replace trend= highschoolentryyear - 2002 if state16==24
replace trend= highschoolentryyear - 2006 if state16==25
replace trend= highschoolentryyear - 2000 if state16==26
replace trend= highschoolentryyear - 2009 if state16==27
replace trend= highschoolentryyear - 2008 if state16==28
replace trend= highschoolentryyear - 2008 if state16==29
replace trend= highschoolentryyear - 2006 if state16==30
replace trend= highschoolentryyear - 2004 if state16==32
replace trend= highschoolentryyear - 2006 if state16==33
replace trend= highschoolentryyear - 2003 if state16==35
replace trend= highschoolentryyear - 2004 if state16==37
replace trend= highschoolentryyear - 2006 if state16==38
replace trend= highschoolentryyear - 2006 if state16==39
replace trend= highschoolentryyear - 2002 if state16==42
replace trend= highschoolentryyear - 2006 if state16==44
replace trend= highschoolentryyear - 2005 if state16==45
replace trend= highschoolentryyear - 2005 if state16==46
replace trend= highschoolentryyear - 2007 if state16==47
replace trend= highschoolentryyear - 2009 if state16==48
replace trend= highschoolentryyear - 2003 if state16==51
replace trend= highschoolentryyear - 2008 if state16==54
replace trend= highschoolentryyear - 2003 if state16==56

gen cohort1=cohort-1981
tab state16, gen(state16)
forvalues i=1/50 {
gen trend_`i' = state16`i'*cohort1
}
global statespecifictrends "trend_2 trend_3 trend_4 trend_5 trend_6 trend_7 trend_8 trend_9 trend_10 trend_11 trend_12 trend_13 trend_14 trend_15 trend_16 trend_17 trend_18 trend_19 trend_20 trend_21 trend_22 trend_23 trend_24 trend_25 trend_26 trend_27 trend_28 trend_29 trend_30 trend_31 trend_32 trend_33 trend_34 trend_35 trend_36 trend_37 trend_38 trend_39 trend_40 trend_41 trend_42 trend_43 trend_44 trend_45 trend_46 trend_47 trend_48 trend_49 trend_50"

gen cohort1_q=cohort1*cohort1
forvalues i=1/50 {
gen trend_quad_`i' = state16`i'*cohort1_q
}
global statespecifictrends_q "trend_quad_2 trend_quad_3 trend_quad_4 trend_quad_5 trend_quad_6 trend_quad_7 trend_quad_8 trend_quad_9 trend_quad_10 trend_quad_11 trend_quad_12 trend_quad_13 trend_quad_14 trend_quad_15 trend_quad_16 trend_quad_17 trend_quad_18 trend_quad_19 trend_quad_20 trend_quad_21 trend_quad_22 trend_quad_23 trend_quad_24 trend_quad_25 trend_quad_26 trend_quad_27 trend_quad_28 trend_quad_29 trend_quad_30 trend_quad_31 trend_quad_32 trend_quad_33 trend_quad_34 trend_quad_35 trend_quad_36 trend_quad_37 trend_quad_38 trend_quad_39 trend_quad_40 trend_quad_41 trend_quad_42 trend_quad_43 trend_quad_44 trend_quad_45 trend_quad_46 trend_quad_47 trend_quad_48 trend_quad_49 trend_quad_50"

gen closestate10=0
replace closestate10=1 if state16==4 | state16==5 | state16==10 | state16==12 | state16==13 | state16==15 | state16==16 | state16==17 | state16==18 | state16==19 | state16==23 | state16==25 | state16==29 | state16==30 | state16==33 | state16==37 | state16==40 |  state16==41 |  state16==44 |  state16==51 |  state16==56 

gen onereform=0
replace onereform=1 if state16==5 | state16==9 | state16==10 | state16==11 | state16==12 | state16==13 | state16==15 | state16==17 | state16==23 | state16==26 | state16==30 | state16==32 | state16==33 | state16==35 | state16==37 | state16==42 | state16==44 | state16==46 | state16==48 | state16==51 | state16==56
replace onereform=. if state16==.

gen largestate=0
replace largestate=1 if state16==6 | state16==48 | state16==12 | state16==36 | state16==42 | state16==17 | state16==39 | state16==13 | state16==37 | state16==26 | state16==34 | state16==51 | state16==53 | state16==4 | state16==25 | state16==47 | state16==18 | state16==24 | state16==29 | state16==55
replace largestate=. if state16==.

gen textstate=0
replace textstate=1 if state16==2 | state16==5 | state16==6 | state16==8 | state16==9 | state16==10 | state16==12| state16==13| state16==16| state16==17| state16==25| state16==26| state16==27| state16==29| state16==31| state16==32| state16==34| state16==36| state16==37 | state16==39| state16==41| state16==44| state16==46| state16==49| state16==50| state16==51| state16==55
replace textstate=. if state16==.

***prepare controls

gen female=0
replace female=1 if sex==2
label variable female "Female"

gen race_white=0
replace race_white=1 if race==1
label variable race_white "Race/Ethnicity: White"

gen race_black=0
replace race_black=1 if race==2
label variable race_black "Race/Ethnicity: Black"

gen race_other=0
replace race_other=1 if race==3
label variable race_other "Race/Ethnicity: Other"

recode hispanic (1=0)
replace hispanic=1 if hispanic>1
label variable hispanic "Race/Ethnicity: Hispanic"

rename res16 rural
recode rural (1=1) (2=1) (3=1) (4=0) (5=0) (6=0)
label define rural 1 "Rural" 0 "Urban"
label values rural rural
label variable rural "Raised in Rural Area"

recode padeg (.d=.) (.i=.) (.n=.)
recode madeg (.d=.) (.i=.) (.n=.)
gen pareduc_missing=0
replace pareduc_missing=1 if padeg==. & madeg==.
label variable pareduc_missing "Parental Education: Missing"

gen pareduc_nohs=0
replace pareduc_nohs=1 if (padeg==0 & madeg==0) | (padeg==0 & madeg==.) | (padeg==. & madeg==0)
label variable pareduc_nohs "Parental Education: No Highschool"

gen pareduc_hs=0
replace pareduc_hs=1 if (padeg==1 & madeg==0) | (padeg==0 & madeg==1) | (padeg==1 & madeg==1) | (padeg==1 & madeg==.) | (padeg==. & madeg==1)
label variable pareduc_hs "Parental Education: Highschool"

gen pareduc_hsmore=0
replace pareduc_hsmore=1 if padeg>1 & padeg!=.
replace pareduc_hsmore=1 if madeg>1 & madeg!=.
replace pareduc_hsmore=0 if padeg==. | madeg==.

label variable pareduc_hsmore "Parental Education: More than Highschool"

recode parborn (0=1) (8=0) (7=0) (6=0) (5=0) (4=0) (3=0) (2=0) (1=0)
gen parborn_us=0
replace parborn_us=1 if parborn==1
label variable parborn_us "Parents born in US"

gen parborn_abroad=0
replace parborn_abroad=1 if parborn==0
label variable parborn_abroad "Parents born abroad"

gen parborn_missing=0
replace parborn_missing=1 if parborn==.n | parborn==.i
label variable parborn_missing "Parents born: Missing"

gen family16_both=0
replace family16_both=1 if family16==1 
label variable family16_both "Growing up: Both Parents"

gen family16_parstep=0
replace family16_parstep=1 if family16==2 | family16==3 
label variable family16_parstep "Growing up: One Parent, one Stepparent"

gen family16_singlep=0
replace family16_singlep=1 if family16==4 | family16==5 
label variable family16_singlep "Growing up: Single Parent"

gen family16_other=0
replace family16_other=1 if family16>5
label variable family16_other "Growing up: Other"

tab relig16,gen(relig16dummy)
label variable relig16dummy1 "Raised as Protestant"
label variable relig16dummy2 "Raised as Catholic"
label variable relig16dummy3 "Raised as Jew"
label variable relig16dummy4 "Raised as Non-Religious"
label variable relig16dummy5 "Raised as Other"
label variable relig16dummy6 "Raised as Buddhist"
label variable relig16dummy7 "Raised as Hindu"
label variable relig16dummy8 "Raised as Other Eastern Rel."
label variable relig16dummy9 "Raised as Muslim"
label variable relig16dummy10 "Raised as Orthodox-Christian"
label variable relig16dummy11 "Raised as Christian"
label variable relig16dummy12 "Raised as Native American"
label variable relig16dummy13 "Raised as Inter-Nondenominational"

tab denom16,gen(denom16dummy)

gen prot_baptist=.
replace prot_baptist=0 if relig16!=.
replace prot_baptist=1 if relig16dummy1==1 & denom16>=10 & denom16<=18
label variable prot_baptist "Raised as Protestant: Baptist"

gen prot_methodist=.
replace prot_methodist=0 if relig16!=.
replace prot_methodist=1 if relig16dummy1==1 & denom16>=20 & denom16<=28
label variable prot_methodist "Raised as Protestant: Methodist"

gen prot_lutheran=.
replace prot_lutheran=0 if relig16!=.
replace prot_lutheran=1 if relig16dummy1==1 & denom16>=30 & denom16<=38
label variable prot_lutheran "Raised as Protestant: Lutheran"

gen prot_presbyterian=.
replace prot_presbyterian=0 if relig16!=.
replace prot_presbyterian=1 if relig16dummy1==1 & denom16>=40 & denom16<=48
label variable prot_presbyterian "Raised as Protestant: Presbyterian"

gen prot_episcopals=.
replace prot_episcopals=0 if relig16!=.
replace prot_episcopals=1 if relig16dummy1==1 & denom16>=50 & denom16<=58
label variable prot_episcopals "Raised as Protestant: Episcopal"

gen prot_evangelicals=.
replace prot_evangelicals=0 if relig16!=.
replace prot_evangelicals=1 if relig16dummy1==1 & denom16==60 
label variable prot_evangelicals "Raised as Protestant: Evangelical"

gen prot_anyother=.
replace prot_anyother=0 if relig16!=.
replace prot_anyother=1 if relig16dummy1==1 & denom16>60 
label variable prot_anyother "Raised as Protestant: Any Other"

gen mainline=.
replace mainline=0 if relig16!=.
replace mainline=1 if relig16dummy1==1 & prot_evangelicals==0
label variable mainline "Raised as Protestant: Mainline"

gen surveyyear=cohort+age

gen pareduc_nohs_ni=0
replace pareduc_nohs_ni=1 if (padeg==0 & madeg==0) | (padeg==0 & madeg==.) | (padeg==. & madeg==0)
replace pareduc_nohs_ni=. if padeg==. & madeg==.
label variable pareduc_nohs_ni "Parental Education: No Highschool"

gen pareduc_hs_ni=0
replace pareduc_hs_ni=1 if (padeg==1 & madeg==0) | (padeg==0 & madeg==1) | (padeg==1 & madeg==1) | (padeg==1 & madeg==.) | (padeg==. & madeg==1)
replace pareduc_hs_ni=. if padeg==. & madeg==.
label variable pareduc_hs_ni "Parental Education: Highschool"

gen pareduc_hsmore_ni=0
replace pareduc_hsmore_ni=1 if padeg>1 & padeg!=.
replace pareduc_hsmore_ni=1 if madeg>1 & madeg!=.
replace pareduc_hsmore_ni=. if padeg==. & madeg==.
label variable pareduc_hsmore_ni "Parental Education: More than Highschool"

gen parborn_us_ni=0
replace parborn_us_ni=1 if parborn==1
replace parborn_us_ni=. if parborn==.n | parborn==.i
label variable parborn_us_ni "Parents born in US"

gen parborn_abroad_ni=0
replace parborn_abroad_ni=1 if parborn==0
replace parborn_abroad_ni=. if parborn==.n | parborn==.i
label variable parborn_abroad_ni "Parents born abroad"

global controls "female race_black race_other hispanic rural parborn_abroad parborn_missing pareduc_hs pareduc_hsmore pareduc_missing family16_parstep family16_single family16_other mainline prot_evangelicals relig16dummy2 relig16dummy3  relig16dummy5 relig16dummy6 relig16dummy7 relig16dummy8 relig16dummy9 relig16dummy10 relig16dummy11 relig16dummy12 relig16dummy13 i.surveyyear"

***prepare event studies

gen zero=0

gen pre78=0
replace pre78=1 if trend==-7 | trend<=-8
replace pre78=. if trend==.

gen pre56=0
replace pre56=1 if trend==-5 | trend==-6
replace pre56=. if trend==.

gen pre34=0
replace pre34=1 if trend==-3 | trend==-4
replace pre34=. if trend==.

gen pre12=0
replace pre12=1 if trend==-1 | trend==-2
replace pre12=. if trend==.

gen post01=0
replace post01=1 if trend==0 | trend==1
replace post01=. if trend==.

gen post23=0
replace post23=1 if trend==2| trend==3
replace post23=. if trend==.

gen post45=0
replace post45=1 if trend==4| trend>=5
replace post45=. if trend==.

gen evo_approval_conv = evo_approval
replace evo_approval_conv = evo_approval_conv*(-1) if less_evolution==1

***merge other datasets

merge m:1 highschoolentryyear state16 using "${path}\data\states\governors19912009.dta"
drop _merge
drop if year==.

***prepare sample and save data

reg evo_approval evo_score $controls i.state16 i.cohort, vce(cluster state16)
gen sample_gss=e(sample)

save "${path}\data\gss\gss_ready.dta", replace

***preamble

clear
clear matrix
clear mata
set maxvar 30000

***load data

use "${path}\data\gss\gss.dta"


***prepare outcomes (scientific, religious and political outcomes are coded such that an increase in the variable implies an increase in scientific correctness, religiosity, political conservatism)

gen evo_approval = evolved
recode evo_approval (2=0) (.d=0) (.n=.) (.i=.)
label variable evo_approval "Evolution Belief"

gen evolved1_recode = evolved1
recode evolved1_recode (2=0) (.d=0) (.n=.)  (.i=.)

gen evolved2_recode = evolved2
recode evolved2_recode (2=0) (.d=0) (.n=.)  (.i=.)

replace evo_approval= evolved1_recode if evo_approval==.
replace evo_approval= evolved2_recode if evo_approval==.

gen evo_approval2 = evolved
recode evo_approval2 (2=0) (.d=.) (.n=.) (.i=.)
label variable evo_approval2 "Evolution Belief"

gen evolved1_recode2 = evolved1
recode evolved1_recode2 (2=0) (.d=.) (.n=.)  (.i=.)

gen evolved2_recode2 = evolved2
recode evolved2_recode2 (2=.) (.d=.) (.n=.)  (.i=.)

replace evo_approval2= evolved1_recode2 if evo_approval2==.
replace evo_approval2= evolved2_recode2 if evo_approval2==.

gen evo_approval3 = evolved
recode evo_approval3 (2=0) (.d=0) (.n=.) (.i=.)
label variable evo_approval3 "Evolution Belief"

gen evolved1_recode3 = evolved1
recode evolved1_recode3 (2=0) (.d=0) (.n=.)  (.i=.)

replace evo_approval3= evolved1_recode3 if evo_approval3==.

recode hotcore (2=0)  (.d=0) (.n=.) (.i=.)
label variable hotcore "Earth"
recode radioact (2=1) (1=0) (.d=0) (.n=.) (.i=.)
label variable radioact "Radioactivity"
recode boyorgrl (2=0)  (.d=0) (.n=.) (.i=.)
label variable boyorgrl "Reproduction"
recode lasers (2=1) (1=0) (.d=0) (.n=.) (.i=.)
label variable lasers "Lasers"
recode electron (2=0) (.d=0) (.n=.) (.i=.)
label variable electron "Electrons"
recode viruses (2=1) (1=0) (.d=0) (.n=.) (.i=.)
label variable viruses "Antibiotics"
recode bigbang (2=0) (.d=0) (.n=.) (.i=.)
recode bigbang1 (2=0) (.d=0) (.n=.) (.i=.)
recode bigbang2 (2=0) (.d=0) (.n=.) (.i=.)
replace bigbang=bigbang1 if bigbang==.
replace bigbang=bigbang2 if bigbang==.
label variable bigbang "Universe"
recode condrift (2=0) (.d=0) (.n=.) (.i=.)
label variable condrift "Tectonics"
recode earthsun (2=0) (.d=0) (.n=.) (.i=.)
label variable earthsun "Sun"

egen placebo_share_correct=rowmean(hotcore radioact boyorgrl lasers electron viruses bigbang condrift earthsun)
label variable placebo_share_correct "Non-Evolution Scientific Topics: Average"

recode god (6=1) (5=1) (4=1) (3=1) (2=0) (1=0) (.d=0) (.n=.) (.i=.)
label variable god "God"

recode bible (1=1) (2=1) (3=0) (4=0) (.d=0) (.n=.) (.i=.)
label variable bible "Bible"

recode postlife (1=1) (2=0) (.d=0) (.n=.) (.i=.) 
label variable postlife "Afterlife"

recode reborn (2=0) (.d=0) (.n=.) (.i=.)
label variable reborn "Rebirth"

recode reliten (4=0) (3=1) (2=0) (1=1) (.d=0) (.n=.) (.i=.)
label variable reliten "Strong Believer"

recode relig (2=1) (3=1) (4=0) (5=1) (6=1) (7=1) (8=1) (9=1) (10=1) (11=1) (12=1) (13=1) (98=0) (.d=0) (99=.) (.i=.)
label variable relig "Religious Affiliation"

recode attend (9=0) (8=1) (7=1) (6=1) (5=1) (4=1) (3=0) (2=0) (1=0) (.d=0) (.n=.) (.i=.)
label variable attend "Church-going"

recode relactiv (11=1) (10=1) (9=1) (8=1) (7=1) (6=1) (5=1) (4=0) (3=0) (2=0) (1=0) (.d=0) (.n=.) (.i=.)
label variable relactiv "Church Activities"

recode pray (6=0) (5=0) (4=1) (3=1) (2=1) (1=1) (.d=0) (.n=.) (.i=.)  
label variable pray "Personal Prayer"

recode savesoul (2=0) (.d=0) (.n=.) (.i=.)
label variable savesoul "Missionize"

recode sprtprsn (4=0) (3=0) (2=1) (1=1) (.d=0) (.n=.) (.i=.)
label variable sprtprsn "Spiritual Person"

recode relpersn (4=0) (3=0) (2=1) (1=1) (.d=0) (.n=.) (.i=.)
label variable relpersn "Religious Person"

recode fund (3=0) (2=0) (1=1) (.d=0) (.n=.) (.i=.)
label variable fund "Fundamentalist"

egen placebo_religiosity_average=rowmean(god bible postlife reborn reliten relig attend relactiv pray savesoul sprtprsn relpersn fund)
label variable placebo_religiosity_average "Religious Outcomes: Average"

recode partyid (1=0) (2=0) (3=0) (4=1) (5=1) (6=1) (7=0) (.d=0) (.i=.)
label variable partyid "Republican"

recode polviews (1=0) (2=0) (3=0) (4=0) (5=1) (6=1) (7=1) (.d=0) (.i=.)
label variable polviews "Conservative"

recode prayer (2=1) (1=0) (.d=0) (.n=.) (.i=.)  
label variable prayer "Prayer in Public Schools"

recode sexeduc (2=0) (3=0) (.d=0) (.n=.) (.i=.) 
label variable sexeduc "Sex Education in Public Schools"

recode marhomo (2=1) (3=0) (4=0) (5=0) (.d=0) (.i=.)
label variable marhomo "Same-Sex Marriage"

recode abany (2=0) (.d=0) (.i=.)
label variable abany "Abortion"

recode grass (2=0) (.d=0) (.i=.)
label variable grass "Marijuana Legalization"

recode cappun (2=0) (.d=0) (.i=.)
label variable cappun "Capital Punishment"

recode gunlaw (2=0) (.d=0) (.i=.)
label variable gunlaw "Gun Control"

recode letin1 (1=1) (2=1) (3=0) (4=0) (5=0) (.d=0) (.i=.)
recode letin1a (1=1) (2=1) (3=0) (4=0) (5=0) (.d=0) (.i=.)
replace letin1=letin1a if letin1==.
label variable letin1 "Immigration"

recode natenvir (1=1) (2=0) (3=0) (.d=0) (.i=.)
recode natenviy (1=1) (2=0) (3=0) (.d=0) (.i=.)
replace natenvir=natenviy if natenvir==.
label variable natenvir "Environment"

recode natenrgy (1=1) (2=0) (3=0) (.d=0) (.i=.)
label variable natenrgy "Alternative Energy Sources"

recode nateduc (1=1) (2=0) (3=0) (.d=0) (.i=.)
recode nateducy (1=1) (2=0) (3=0) (.d=0) (.i=.)
replace nateduc=nateducy if nateduc==.
label variable nateduc "Education"

recode natsci (1=1) (2=0) (3=0) (.d=0) (.i=.)
label variable natsci "Scientific Research"

recode eqwlth (1=1) (2=1) (3=1) (4=0) (5=0) (6=0) (7=0) (.d=0) (.i=.)
label variable eqwlth "Reducing Income Differences"

recode natfare (1=1) (2=0) (3=0) (.d=0) (.i=.)
recode natfarey (1=1) (2=0) (3=0) (.d=0) (.i=.)
replace natfare=natfarey if natfare==.
label variable natfare "Assistance to the Poor"

recode natrace (1=1) (2=0) (3=0) (.d=0) (.i=.)
recode natracey (1=1) (2=0) (3=0) (.d=0) (.i=.)
replace natrace=natracey if natrace==.
label variable natrace "Conditions of Blacks"

foreach v of varlist partyid polviews prayer sexeduc marhomo abany grass cappun gunlaw letin1 natenvir natenrgy nateduc natsci eqwlth natfare natrace {
tab polviews, sum(`v') 
}

foreach v of varlist sexeduc marhomo abany grass gunlaw letin1 natenvir natenrgy nateduc natsci eqwlth natfare natrace {
gen `v'_recode = `v'
recode `v'_recode (1=0) (0=1)
}

foreach v of varlist partyid polviews prayer cappun {
gen `v'_recode = `v'
}

egen placebo_political_average=rowmean(partyid_recode polviews_recode prayer_recode sexeduc_recode marhomo_recode abany_recode grass_recode cappun_recode gunlaw_recode letin1_recode natenvir_recode natenrgy_recode nateduc_recode natsci_recode eqwlth_recode natfare_recode natrace_recode)
label variable placebo_political_average "Political Outcomes: Average"

label variable partyid_recode "Republican"
label variable polviews_recode "Conservative"
label variable prayer_recode "Prayer in Public Schools"
label variable sexeduc_recode "Sex Education in Public Schools"
label variable marhomo_recode "Same-Sex Marriage"
label variable abany_recode "Abortion"
label variable grass_recode "Marijuana Legalization"
label variable cappun_recode "Capital Punishment"
label variable gunlaw_recode "Gun Control"
label variable letin1_recode "Immigration"
label variable natenvir_recode "Environment"
label variable natenrgy_recode "Alternative Energy Sources"
label variable nateduc_recode "Education"
label variable natsci_recode "Scientific Research"
label variable eqwlth_recode "Reducing Income Differences"
label variable natfare_recode "Assistance to the Poor"
label variable natrace_recode "Conditions of Blacks"

recode consci (1=1) (2=1) (3=0) (.d=0) (.i=.)
label variable consci "Confidence in Science"

recode intsci (1=1) (2=1) (3=0) (.d=0) (.i=.)
label variable intsci "Interest in Science"

recode advfront (1=1) (2=1) (3=0) (4=0) (.d=0) (.i=.)
label variable advfront "Science is Necessary"

egen placebo_share_correct_sciatt=rowmean(consci intsci advfront)
label var placebo_share_correct_sciatt "Science Attitudes: Average"

***prepare treatments

rename fipsstat16 state16

gen highschoolentryyear=cohort+14

gen evolution_score=.
replace evolution_score= 9 if state16==1 & highschoolentryyear<2005
replace evolution_score= 21 if state16==1 & highschoolentryyear>=2005
replace evolution_score= 48 if state16==2 & highschoolentryyear<2006
replace evolution_score= 59 if state16==2 & highschoolentryyear>=2006
replace evolution_score= 82 if state16==4 & highschoolentryyear<2005
replace evolution_score= 82 if state16==4 & highschoolentryyear>=2005
replace evolution_score= 55 if state16==5 & highschoolentryyear<2005
replace evolution_score= 66 if state16==5 & highschoolentryyear>=2005
replace evolution_score= 100 if state16==6
replace evolution_score= 86 if state16==8 & highschoolentryyear<2009
replace evolution_score= 82 if state16==8 & highschoolentryyear>=2009
replace evolution_score= 100 if state16==9 & highschoolentryyear<2004
replace evolution_score= 59 if state16==9 & highschoolentryyear>=2004
replace evolution_score= 91 if state16==10 & highschoolentryyear<2006
replace evolution_score= 80 if state16==10 & highschoolentryyear>=2006
replace evolution_score= 80 if state16==11 & highschoolentryyear<2006
replace evolution_score= 96 if state16==11 & highschoolentryyear>=2006
replace evolution_score= 16 if state16==12 & highschoolentryyear<2008
replace evolution_score= 91 if state16==12 & highschoolentryyear>=2008
replace evolution_score= 7 if state16==13 & highschoolentryyear<2004
replace evolution_score= 66 if state16==13 & highschoolentryyear>=2004
replace evolution_score= 91 if state16==15 & highschoolentryyear<2005
replace evolution_score= 75 if state16==15 & highschoolentryyear>=2005
replace evolution_score= 82 if state16==16 & highschoolentryyear<2007
replace evolution_score= 82 if state16==16 & highschoolentryyear>=2007
replace evolution_score= 45 if state16==17 & highschoolentryyear<2004
replace evolution_score= 82 if state16==17 & highschoolentryyear>=2004
replace evolution_score= 100 if state16==18 & highschoolentryyear<2006
replace evolution_score= 96 if state16==18 & highschoolentryyear>=2006
replace evolution_score= 77 if state16==19 & highschoolentryyear>=2007
replace evolution_score= 0 if state16==20 & highschoolentryyear<2007
replace evolution_score= 96 if state16==20 & highschoolentryyear>=2007
replace evolution_score= 55 if state16==21 & highschoolentryyear<2006
replace evolution_score= 55 if state16==21 & highschoolentryyear>=2006
replace evolution_score= 64 if state16==22 & highschoolentryyear<2005
replace evolution_score= 27 if state16==22 & highschoolentryyear>=2005
replace evolution_score= 30 if state16==23 & highschoolentryyear<2007
replace evolution_score= 68 if state16==23 & highschoolentryyear>=2007
replace evolution_score= 77 if state16==24 & highschoolentryyear<2002
replace evolution_score= 73 if state16==24 & highschoolentryyear>=2002
replace evolution_score= 82 if state16==25 & highschoolentryyear<2006
replace evolution_score= 84 if state16==25 & highschoolentryyear>=2006
replace evolution_score= 84 if state16==26 & highschoolentryyear<2000
replace evolution_score= 80 if state16==26 & highschoolentryyear>=2000
replace evolution_score= 86 if state16==27 & highschoolentryyear<2009
replace evolution_score= 89 if state16==27 & highschoolentryyear>=2009
replace evolution_score= 5 if state16==28 & highschoolentryyear<2008
replace evolution_score= 86 if state16==28 & highschoolentryyear>=2008
replace evolution_score= 82 if state16==29 & highschoolentryyear<2008
replace evolution_score= 78 if state16==29 & highschoolentryyear>=2008
replace evolution_score= 82 if state16==30 & highschoolentryyear<2006
replace evolution_score= 75 if state16==30 & highschoolentryyear>=2006
replace evolution_score= 66 if state16==31 
replace evolution_score= 70 if state16==32 & highschoolentryyear<2004
replace evolution_score= 77 if state16==32 & highschoolentryyear>=2004
replace evolution_score= 23 if state16==33 & highschoolentryyear<2006
replace evolution_score= 91 if state16==33 & highschoolentryyear>=2006
replace evolution_score= 100 if state16==34 & highschoolentryyear<2002
replace evolution_score= 100 if state16==34 & highschoolentryyear>=2002
replace evolution_score= 73 if state16==35 & highschoolentryyear<2003
replace evolution_score= 91 if state16==35 & highschoolentryyear>=2003
replace evolution_score= 68 if state16==36 
replace evolution_score= 100 if state16==37 & highschoolentryyear<2004
replace evolution_score= 82 if state16==37 & highschoolentryyear>=2004
replace evolution_score= 9 if state16==38 & highschoolentryyear<2006
replace evolution_score= 64 if state16==38 & highschoolentryyear>=2006
replace evolution_score= 30 if state16==39 & highschoolentryyear<2006
replace evolution_score= 86 if state16==39 & highschoolentryyear>=2006
replace evolution_score= 25 if state16==40 & highschoolentryyear<2005
replace evolution_score= 25 if state16==40 & highschoolentryyear>=2005
replace evolution_score= 82 if state16==41 & highschoolentryyear<2009
replace evolution_score= 82 if state16==41 & highschoolentryyear>=2009
replace evolution_score= 91 if state16==42 & highschoolentryyear<2002
replace evolution_score= 96 if state16==42 & highschoolentryyear>=2002
replace evolution_score= 100 if state16==44 & highschoolentryyear<2006
replace evolution_score= 82 if state16==44 & highschoolentryyear>=2006
replace evolution_score= 95 if state16==45 & highschoolentryyear<2005
replace evolution_score= 91 if state16==45 & highschoolentryyear>=2005
replace evolution_score= 82 if state16==46 & highschoolentryyear<2005
replace evolution_score= 77 if state16==46 & highschoolentryyear>=2005
replace evolution_score= 2 if state16==47 & highschoolentryyear<2007
replace evolution_score= 55 if state16==47 & highschoolentryyear>=2007
replace evolution_score= 64 if state16==48 & highschoolentryyear<2009
replace evolution_score= 46 if state16==48 & highschoolentryyear>=2009
replace evolution_score= 82 if state16==49 & highschoolentryyear<2003
replace evolution_score= 82 if state16==49 & highschoolentryyear>=2003
replace evolution_score= 86 if state16==50 & highschoolentryyear<2000
replace evolution_score= 86 if state16==50 & highschoolentryyear>=2000
replace evolution_score= 50 if state16==51 & highschoolentryyear<2003
replace evolution_score= 68 if state16==51 & highschoolentryyear>=2003
replace evolution_score= 86 if state16==53 & highschoolentryyear<2005
replace evolution_score= 86 if state16==53 & highschoolentryyear>=2005
replace evolution_score= 2 if state16==54 & highschoolentryyear<2008
replace evolution_score= 46 if state16==54 & highschoolentryyear>=2008
replace evolution_score= 55 if state16==55 
replace evolution_score= 36 if state16==56 & highschoolentryyear<2003
replace evolution_score= 61 if state16==56 & highschoolentryyear>=2003
gen evo_score=evolution_score/100
label variable evo_score "Evolution Score"

gen textstate=0
replace textstate=1 if state16==2 | state16==5 | state16==6 | state16==8 | state16==9 | state16==10 | state16==12| state16==13| state16==16| state16==17| state16==25| state16==26| state16==27| state16==29| state16==31| state16==32| state16==34| state16==36| state16==37 | state16==39| state16==41| state16==44| state16==46| state16==49| state16==50| state16==51| state16==55
replace textstate=. if state16==.

drop if cohort==.n
drop if state16==.
drop if state16<1
drop if evo_approval==.
drop if evo_score==.

gen pop_textstate = 0
replace pop_textstate = 1 if textstate==1

gen sample_textstate = .
replace sample_textstate=1 if cohort!=.n & state16!=. & state16>=1 & highschoolentryyear>1990 & highschoolentryyear<2010 & evo_approval!=. & evo_score!=. & year!=. & textstate==1
replace sample_textstate=0 if cohort!=.n & state16!=. & state16>=1 & highschoolentryyear>1990 & highschoolentryyear<2010 & evo_approval!=. & evo_score!=. & year!=. & textstate==0

order sample_textstate pop_textstate textstate cohort
sort sample_textstate pop_textstate textstate cohort

save "${path}\data\gss\gss_ready_table_a-xv.dta", replace